import os
from openpyxl import Workbook

def get_pdf_files(root_dir):
    pdf_files = []
    for root, dirs, files in os.walk(root_dir):
        for file in files:
            if file.endswith(".pdf"):
                pdf_files.append(os.path.join(root, file))
    return pdf_files

def save_to_excel(file_list, output_path):
    wb = Workbook()
    ws = wb.active

    for i, file in enumerate(file_list):
        ws.cell(row=i+1, column=1, value=file)

    wb.save(output_path)

# 指定文件夹路径
folder_path = "./202112-202211"

# 获取指定文件夹路径下的所有PDF文件
pdf_files = get_pdf_files(folder_path)

# 输出到Excel
output_file = "./output.xlsx"
save_to_excel(pdf_files, output_file)
print("已将PDF文件输出到Excel：", output_file)
